# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=mautrix-whatsapp
pkgver=0.10.7
pkgrel=1
pkgdesc="Matrix-WhatsApp puppeting bridge"
url="https://maunium.net/go/mautrix-whatsapp"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/whatsapp/archive/v$pkgver.tar.gz
	mautrix-whatsapp.initd
	mautrix-whatsapp.confd
	default-log-dir.patch
	"
builddir="$srcdir/whatsapp-$pkgver"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	local _goldflags="
		-X main.Tag=$pkgver
		-X 'main.BuildTime=$(date '+%b %_d %Y, %H:%M:%S')'
		"

	go build -ldflags "$_goldflags"
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-whatsapp \
		-t "$pkgdir"/usr/bin/
	install -Dm644 example-config.yaml \
		-t "$pkgdir"/etc/mautrix-whatsapp/

	install -Dm755 "$srcdir"/mautrix-whatsapp.initd \
		"$pkgdir"/etc/init.d/mautrix-whatsapp
	install -Dm644 "$srcdir"/mautrix-whatsapp.confd \
		"$pkgdir"/etc/conf.d/mautrix-whatsapp
}

sha512sums="
b0d3d572bbd29e5b4391662fd3fa1e6849d9f51a094257072883ec2797972defbfc3e22ab6fa0354b634045974bbe8a6d090699330c3ace1021f944757a766f3  mautrix-whatsapp-0.10.7.tar.gz
320ec426f033e93297bb3dd2ebe6996a9a677c53e76e8eb6d4b6f2bb24c1c756ef8d38d2dbb0d038369507fd9bf4864e73ab86783be3f6bbca150fe46a669841  mautrix-whatsapp.initd
9349b660273c63d2973f1b99ddbd98469dddc098157380603210159f17d3cb1eb55e71dbd21550b20d40831f4da320225e7c03441667e2750e30a2e1fa03acfe  mautrix-whatsapp.confd
d5b66b40dde25f24986788669b91dfafe2f35f901b87ff30bfe8c8ab663ebbbe9bd10ac974f73115abd935eb0f27d5645fcbe641a6c6925c24eaa8c7fa9ab6b7  default-log-dir.patch
"
